/*
 * Vorschläge in Abhängigkeit der Wortlänge:
 *   -> Wörterstatistic aggregieren
 */
package complet.app.tool.experiment;

import complet.helper.IOHelper;
import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.IOException;
import java.util.TreeMap;

public class experiment1 {

    private static BufferedReader ws1 = IOHelper.openReadFile("E:\\paul\\Dokumente\\MyDocuments\\NetBeans Workspace\\Completion\\stats\\225_250T\\WordStat_1.log");
    private static BufferedReader ws2 = IOHelper.openReadFile("E:\\paul\\Dokumente\\MyDocuments\\NetBeans Workspace\\Completion\\stats\\225_250T\\WordStat_2.log");
    private static BufferedReader ws3 = IOHelper.openReadFile("E:\\paul\\Dokumente\\MyDocuments\\NetBeans Workspace\\Completion\\stats\\225_250T\\WordStat_3.log");
    private static TreeMap<String, Integer> tm1 = new TreeMap<String, Integer>();
    private static TreeMap<String, Integer> tm2 = new TreeMap<String, Integer>();
    private static TreeMap<String, Integer> tm3 = new TreeMap<String, Integer>();
    private static BufferedWriter out1 = IOHelper.openWriteFile("E:\\paul\\Dokumente\\MyDocuments\\NetBeans Workspace\\Completion\\stats\\225_250T\\experiment1\\WordStat_1.dat");
    private static BufferedWriter out2 = IOHelper.openWriteFile("E:\\paul\\Dokumente\\MyDocuments\\NetBeans Workspace\\Completion\\stats\\225_250T\\experiment1\\WordStat_2.dat");
    private static BufferedWriter out3 = IOHelper.openWriteFile("E:\\paul\\Dokumente\\MyDocuments\\NetBeans Workspace\\Completion\\stats\\225_250T\\experiment1\\WordStat_3.dat");

    public static void main(String[] args) {
        try {
            String strLine;
            String line[];
            // Für WordStat1
            while (true && (strLine = ws1.readLine()) != null) {
                line = strLine.split("\t");
                tm1.put(line[0], Integer.parseInt(line[2]));
            }
            // Für WordStat2
            while (true && (strLine = ws2.readLine()) != null) {
                line = strLine.split("\t");
                tm2.put(line[0], Integer.parseInt(line[2]));
            }
            // Für WordStat3
            while (true && (strLine = ws3.readLine()) != null) {
                line = strLine.split("\t");
                tm3.put(line[0], Integer.parseInt(line[2]));
            }
        } catch (IOException ex) {
            IOHelper.logError("(experiment1) Failed to read input file: " + ex.getMessage());
        }

        try {
            out1.write("### Vorschläge in Abhängigkeit von Wortlänge ###\n");
            out2.write("### Vorschläge in Abhängigkeit von Wortlänge ###\n");
            out3.write("### Vorschläge in Abhängigkeit von Wortlänge ###\n");

            int t = 0;
            int ges_1 = 0, ges_2 = 0, ges_3 = 0;
            for (int i = 1; i <= 25; i++) {
                // WordStat1
                t = 0;
                for (String key : tm1.keySet()) {
                    if (key.length() == i) {
                        t += tm1.get(key);
                    }
                }
                ges_1 += t;
                out1.write(i + "    " + t + "\n");
                out1.flush();
                // WordStat2
                t = 0;
                for (String key : tm2.keySet()) {
                    if (key.length() == i) {
                        t += tm2.get(key);
                    }
                }
                ges_2 += t;
                out2.write(i + "    " + t + "\n");
                out2.flush();
                // WordStat3
                t = 0;
                for (String key : tm3.keySet()) {
                    if (key.length() == i) {
                        t += tm3.get(key);
                    }
                }
                ges_3 += t;
                out3.write(i + "    " + t + "\n");
                out3.flush();
            }
            out1.write("### Gesamt: " + ges_1 + " ###");
            out2.write("### Gesamt: " + ges_2 + " ###");
            out3.write("### Gesamt: " + ges_3 + " ###");
            out1.close();
            out2.close();
            out3.close();
        } catch (IOException ex) {
            IOHelper.logError("(experiment1) Failed to write result file: " + ex.getMessage());
        }
    }
}
